/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('facebody', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model DetectIPCPedestrianOptimizedRequest {
  height?: long(name='height'),
  imageData?: bytes(name='imageData'),
  width?: long(name='width'),
}

model DetectIPCPedestrianOptimizedResponseBody = {
  data?: {
    imageInfoList?: [ 
      {
        elements?: [ 
          {
            boxes?: [ long ](name='Boxes'),
            score?: float(name='Score'),
          }
        ](name='Elements'),
      }
    ](name='ImageInfoList'),
  }(name='Data'),
  requestId?: string(name='RequestId'),
}

model DetectIPCPedestrianOptimizedResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DetectIPCPedestrianOptimizedResponseBody(name='body'),
}

/**
  * 行人检测快速版
  *
  * @param request DetectIPCPedestrianOptimizedRequest
  * @param headers map
  * @param runtime runtime options for this request RuntimeOptions
  * @return DetectIPCPedestrianOptimizedResponse
 */
async function detectIPCPedestrianOptimizedWithOptions(request: DetectIPCPedestrianOptimizedRequest, headers: map[string]string, runtime: Util.RuntimeOptions): DetectIPCPedestrianOptimizedResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.height)) {
    body['height'] = request.height;
  }
  if (!Util.isUnset(request.imageData)) {
    body['imageData'] = request.imageData;
  }
  if (!Util.isUnset(request.width)) {
    body['width'] = request.width;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DetectIPCPedestrianOptimized',
    version = '2020-09-10',
    protocol = 'HTTPS',
    pathname = `/viapi/k8s/facebody/detect-ipc-pedestrian-optimized`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
  * 行人检测快速版
  *
  * @param request DetectIPCPedestrianOptimizedRequest
  * @return DetectIPCPedestrianOptimizedResponse
 */
async function detectIPCPedestrianOptimized(request: DetectIPCPedestrianOptimizedRequest): DetectIPCPedestrianOptimizedResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return detectIPCPedestrianOptimizedWithOptions(request, headers, runtime);
}

model ExecuteServerSideVerificationRequest {
  certificateName?: string(name='certificateName'),
  certificateNumber?: string(name='certificateNumber', example='1281739873298172981'),
  facialPictureData?: string(name='facialPictureData', example='/9j/wwew...'),
  facialPictureUrl?: string(name='facialPictureUrl', example='http://xxx.xxx.com/xxx.jpg'),
  sceneType?: string(name='sceneType', example='server'),
}

model ExecuteServerSideVerificationResponseBody = {
  data?: {
    pass?: boolean(name='Pass', example='true'),
    reason?: string(name='Reason'),
    verificationToken?: string(name='VerificationToken', example='6f1f730e732b232ccbdd85abc751****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='CE2FFC8A-6669-4F02-B4DA-95888087FBDC'),
}

model ExecuteServerSideVerificationResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteServerSideVerificationResponseBody(name='body'),
}

async function executeServerSideVerificationWithOptions(request: ExecuteServerSideVerificationRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ExecuteServerSideVerificationResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.certificateName)) {
    body['certificateName'] = request.certificateName;
  }
  if (!Util.isUnset(request.certificateNumber)) {
    body['certificateNumber'] = request.certificateNumber;
  }
  if (!Util.isUnset(request.facialPictureData)) {
    body['facialPictureData'] = request.facialPictureData;
  }
  if (!Util.isUnset(request.facialPictureUrl)) {
    body['facialPictureUrl'] = request.facialPictureUrl;
  }
  if (!Util.isUnset(request.sceneType)) {
    body['sceneType'] = request.sceneType;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteServerSideVerification',
    version = '2020-09-10',
    protocol = 'HTTPS',
    pathname = `/viapi/thirdparty/realperson/execServerSideVerification`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeServerSideVerification(request: ExecuteServerSideVerificationRequest): ExecuteServerSideVerificationResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return executeServerSideVerificationWithOptions(request, headers, runtime);
}

